<?php

  class page_data{

        private $record_count;

        /**
        *@desc
        *@access    private
        *@var        array
        */
        private $data_return;

        private static $instance; 

        static function Instance(){
            if (!isset(self::$instance)) {
                $c = __CLASS__;
                self::$instance = new $c;
            }
            return self::$instance;
        }
        
        public function __construct(){

        }

            /**
            * @desc
            * @access   public
            * @param    int $first_record
            * @param    int $last_record
            * @return   array
            */
            public function get_list($first=null,$last=null){
                $temp=array();
                $i=0;
                if(is_array($this->data_return)){
                    $total_row=count($this->data_return);
                    if(isset($first) && isset($last)){
                        if($first<=$total_row && $first<=$last){
                            if($last>$total_row){
                                foreach ($this->data_return as $key => $value) {
                                    $i++;
                                    if($i>$first){
                                            $temp[$key]=$value;
                                    }
                                }
                            }
                            elseif($last<=$total_row){
                                 foreach ($this->data_return as $key => $value) {
                                    $i++;
                                    if($i>$first && $i<=$last){
                                            $temp[$key]=$value;
                                    }
                                }
                            }
                        }
                    }
                    elseif(isset($first) && !isset($last)){
                        if($first<=$total_row){
                            foreach ($this->data_return as $key => $value) {
                                  $i++;
                                if($i>=$first){
                                        $temp[$key]=$value;
                                }
                            }
                        }
                    }
                    elseif(!isset($first) && isset($last)){
                        if($last<=$total_row){
                             foreach ($this->data_return as $key => $value) {
                                $i++;
                                if($i<=$last){
                                        $temp[$key]=$value;
                                }
                            }
                        }
                        else{
                            $temp=$this->data_return;
                        }
                    }
                }
                return $temp;
            }

            public function get_record_count(){
                return $this->record_count;
            }

            public function set_data_list($data_list){
                $this->data_return=$data_list;
                $this->record_count=count($this->data_return);
            }

            public function __destruct(){
                if(is_object($this)){
                    unset($this);
                }
            }

  }
?>